local ffi = require("ffi")
ffi.cdef[[
    int dogStart();
    void dogStop();
    int getDogMemoryInfo(char* buf, int bufsize);
    void checkDogExpireDate(void(*cb)(int));
    int dogExpireDateStatus();
    void setDogTimerInterval(int interval, int expDateinterval);
    int dogStatus();
    void checkDogStatus(void(*cb)(int));
    int dogCheckExpDateFlag();
]]


local lib = ffi.load('dogservice')


local function updateExpireDateStatusCallBack(status)
    print("The superdog expire date status:", status) 
    if status ~= 0 then
        print("The superdog have arrived expire date! Status: ", status)
    end
end

local function updateSessionStatusCallBack(status)
    print("dog status: ", status) 
    if status ~= 0 then
        print("dog status error! status: ", status)
    end
end

local function start()
    lib.setDogTimerInterval(3, 30)
    lib.dogStart()
    lib.checkDogExpireDate(updateExpireDateStatusCallBack)
    lib.checkDogStatus(updateSessionStatusCallBack)
    local buf = ffi.new('char[?]', 1024)
    if 0 == lib.getDogMemoryInfo(buf, 1024) then
        print("dogMemoryInfo: ", ffi.string(buf)) 
    end
    print("dogExpireDateStatus: ", lib.dogExpireDateStatus())
    print("dogCheckExpDateFlag: ", lib.dogCheckExpDateFlag())
    print("dogStatus: ", lib.dogStatus())
end

local function stop()
    lib.dogStop()
end

start()

io.read()